<template>
  <div>
    <!-- 标题 -->
    <van-cell title="搜索历史">
      <van-icon name="delete-o" @click="isShow = true" v-if="!isShow" />
      <div v-else>
        <span @click="$store.commit('SET_HISTORLES', [])">全部删除</span> &nbsp;
        <span @click="isShow = false">完成</span>
      </div>
    </van-cell>
    <!-- 搜索历史 -->
    <van-cell
      :title="itms"
      v-for="(itms, index) in historles"
      @click="$emit('update-keywodrds', itms)"
      :key="index"
    >
      <van-icon
        name="close"
        v-if="isShow"
        @click="
          $store.commit(
            'SET_HISTORLES',
            $store.state.historles.filter((i) => i !== itms)
          )
        "
      />
    </van-cell>
  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  computed: {
    ...mapState(['historles'])
  },
  data() {
    return {
      isShow: false
    }
  }
}
</script>

<style></style>
